import { JJUtil, JJLog, JJPageUtil } from './mobileClientKernel/util/index.js';
import { JJShowHelper } from "./mobileClientKernel/bizUtil/index.js";
import JJLoginService from './mobileClientKernel/service/loginService/JJLoginService.js'

App({
    onLaunch: function () {
        this.jj_update();
    },

    onShow: function (options) {
    },

    onError: function (msg) {
        JJLog.error('APP onError: ' + msg)
    },

    jj_update: function (options) {
        const updateManager = wx.getUpdateManager()

        updateManager.onCheckForUpdate(function (res) {
            // 请求完新版本信息的回调
            JJLog.log('是否有新版本：' + res.hasUpdate)
        })

        updateManager.onUpdateReady(function () {
            // 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
            wx.showModal({
                title: '更新提示',
                content: '新版本已经准备好，需要立即更新',
                showCancel: false,
                success: function (res) {
                    updateManager.applyUpdate()
                }
            })
        })

        updateManager.onUpdateFailed(function () {
            // 新的版本下载失败
            JJLog.warn('新版本下载失败')
        })
    },

    jj_showMessage: function (title) {
        JJShowHelper.toastMessage(title);
    },

    jj_showLoading() {
        JJShowHelper.showLoading();
    },

    jj_hideLoading() {
        JJShowHelper.hideLoading();
    },

    jj_getCurrentPage: function () {
        return JJPageUtil.getCurrentPage();
    },

    jj_getSupperPage: function () {
        return JJPageUtil.getSupperPage();
    },

    jj_popToRootPage: function () {
        JJPageUtil.popToRootPage();
    },

    jj_getCurrentPagePopIndex: function (route) {
        return JJPageUtil.getCurrentPagePopIndex(route);
    }
})
